package com.gan.springbootdemo2.application;

import lombok.extern.slf4j.Slf4j;

import java.util.ArrayList;
import java.util.List;

@Slf4j
public class MainRun {

    public static void main(String[] args) {
        List<Color> list = new ArrayList<>();
        Color color = new Color();
        color.setColorId(1046L);
        color.setColorCode("001");
        color.setColorName("蓝色");
        list.add(color);
        color = new Color();
        color.setColorId(1046L);
        color.setColorCode("001");
        color.setColorName("蓝色");
        list.add(color);
        color = new Color();
        color.setColorId(1046L);
        color.setColorCode("001");
        color.setColorName("蓝色");
        list.add(color);
        list.forEach(co -> {
            log.info(co.toString());
        });
        list = removeDuplicate(list);
        log.info("--------------------------------------------------------------------------------");
        list.forEach(co -> {
            log.info(co.toString());
        });
    }

    private static List<Color> removeDuplicate(List<Color> list) {
        for (int i = 0; i < list.size() - 1; i++) {
            for (int k = list.size() - 1; k > i; k--) {
                if (list.get(k).getColorId().equals(list.get(i).getColorId())) {
                    list.remove(k);
                }
            }
        }
        return list;
    }
}
